<template>
  <li class="todoitem">
    <div>
      <input type="checkbox" v-model="todo.complete">
      <span>{{todo.title}}</span>
    </div>
    <input type="button" value="删除" @click="delTodoItem"></input>
  </li>
</template>

<script>
export default {
  props: {
    todo: Object,
    index: Number,
    delTodo: Function
  },
  methods: {
    //  绑定一个删除按钮事件，将当前item的index传递给APP
    delTodoItem() {
      const { todo, index, delTodo } = this;
      if (window.confirm(`确认删除${todo.title}吗？`)) {
        //   调用从APP传递过来的删除函数
        delTodo(index);
      }
    }
  }
};
</script>

<style scoped>
.todoitem {
  padding: 0 5px;
  height: 30px;
  margin-top: 1px;
  background: #aeb5be;
  position: relative;

  display: flex;
  justify-content: space-between;
  align-items: center;
}
.todoitem span {
  line-height: 30px;
  margin-left: 15px;
  text-align: center;
}

.todoitem input[type='button'] {
  font-size: 12px;
  text-align: center;
  color: #fff;
  outline: none;
  background: #ff4757;
  height: 25px;
  border: 1px solid transparent;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  margin-right: 15px;
  opacity: 0;
  transform: translateX(20px);
  transition: 0.5s;
}
.todoitem:hover {
  background: #34495e;
  color: #fff;
}
.todoitem:hover input[type='button'] {
  opacity: 1;
  transform: translateX(0);
}
</style>